﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BibliotecaDigital
{
    public partial class fMenu : Form
    {
        private int childFormNumber = 0;
        private bool carregado = false;

        public fMenu()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            fRegInfo fRegInf = new fRegInfo();
            fRegInf.MdiParent = this;
            fRegInf.Show();
        }

        private void fMenu_Load(object sender, EventArgs e)
        {
            String[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                carregado = args[1] == "/sim" ? false : true;
            }
            else
                carregado = true;

            registerApp();
            if (!carregado)
            {
                this.WindowState = FormWindowState.Minimized;
                this.Hide();
                this.ShowInTaskbar = false;
            }
            else
                this.ShowInTaskbar = true;
        }

        private void registerApp()
        {
            Microsoft.Win32.RegistryKey rkApp = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            if (!checkRegSet(rkApp))
                rkApp.SetValue("App", Application.ExecutablePath.ToString() + " /sim");
        }

        private bool checkRegSet(Microsoft.Win32.RegistryKey rk)
        {
            if (rk.GetValue("App") == null)
                return false; //not set
            else return true;   //set
        }

        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            this.ShowInTaskbar = true;            
            carregado = true;
            Show();
        }

        private void fMenu_Resize(object sender, EventArgs e)
        {
            if (!carregado)
            {
                notifyIcon1.Visible = true;
                this.Hide();
                carregado = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            fConsultaInfo fConsInf = new fConsultaInfo();
            fConsInf.MdiParent = this;
            fConsInf.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            fPesqProcesso fPesqProc = new fPesqProcesso();
            fPesqProc.MdiParent = this;
            fPesqProc.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            fConsultaArquivo fPesqArq = new fConsultaArquivo();
            fPesqArq.MdiParent = this;
            fPesqArq.Show();
        }


    }
}
